<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="">
        <input type="file" multiple name="avator" id="avator"   />
        <button>提交</button>
    </form>

    <script>
        const formEle = document.querySelector('form');
        formEle.onsubmit = function(e) {
            e.preventDefault()
            // fromdata对象 用户存储表单数据
            // 1. 创建fromdata对象
            const formData = new FormData(this);

            const xhr = new XMLHttpRequest();
            xhr.open('POST', 'http://localhost:3000/api/users/avator');
            xhr.onload = function() {
                const res = JSON.parse(xhr.responseText);
                console.log(res);
            }
            xhr.send(formData);
            
        }
    </script>
</body>
</html>